package com.zygh.coordinatestore.controller;

import com.zygh.coordinatestore.entity.Coordinate;
import com.zygh.coordinatestore.entity.Gps;
import com.zygh.coordinatestore.service.AsyncService;
import com.zygh.coordinatestore.service.CoordinateService;
import com.zygh.coordinatestore.util.StatisticsServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CoordinateController {
    @Autowired
    private CoordinateService coordinateService;
    @Autowired
    private AsyncService asyncService;
//    @Autowired
//    private GpsService gpsService;
    @Autowired
    private StatisticsServer statisticsServer;

    /**
     * 上传轨迹坐标(格式)
     *113.735041,35.649001;117.804633,35.580633;115.326753,35.709838;118.850556,36.357902;
     * 114.473632,37.548983;114.884482,38.939046;113.927834,41.423798;118.013694,36.134297;
     * 114.444940,36.641906;116.591290,41.013163;117.247467,41.129835;115.058506,38.091939;
     * 114.536375,35.237608;114.355211,35.657877;117.010476,35.798199;115.730233,37.546940;
     * 117.387333,38.824083;115.159570,39.106828;114.663955,36.185254;118.012046,40.980490
     * @param coordinate
     * @return
     */
    @PostMapping("addGps")
    public Integer addGps(Coordinate coordinate) throws Exception {
//        String s = randomLonLat(113.617078, 118.887904, 34.759435, 42.264072);
//        coordinate.setLonLats(s);
        Integer integer = coordinateService.insertSelective(coordinate);
        return integer;
    }

    /**
     * 查询所有坐标轨迹(根据警号)
     *
     * @param police
     * @return
     */
    @GetMapping("findInfoByPolice")
    public List<Coordinate> findInfoByPolice(String police) throws Exception {
        return coordinateService.findInfoByPolice(police);
    }

    /**
     * 根据id修改坐标轨迹
     *
     * @param coordinate
     */
    @GetMapping("updateByPrimaryKeySelective")
    public Integer updateByPrimaryKeySelective(Coordinate coordinate) throws Exception {
        System.out.println("df"+coordinate.getId());
        Integer integer = coordinateService.updateByPrimaryKeySelective(coordinate);
        return integer;
    }

    /**
     * 插入测试
     *
     * @param
     */
    @GetMapping("writeTxt")
    public void writeTxt() throws Exception {
        asyncService.writeTxt();
    }
    /**
     * 更新测试
     *
     * @param
     */
    @GetMapping("writeupdate")
    public void writeupdate() throws Exception {
        asyncService.writeupdate();
    }

//    @GetMapping("findGpsByid")
//    public List<Gps> findGpsByid() {
//        return gpsService.findGpsByid();
//    }


}
